﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO_DTO_WS.DAO;
using DAO_DTO_WS.DTO;

namespace LayoutTemplate
{
    public partial class TinhTrangDonHang : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["ID"].ToString() == "")
                    Response.Redirect("TrangLoi.aspx?Error=2");
                List<DonHangDTO> dsDonHang = new List<DonHangDTO>();
                dsDonHang = DonHangDAO.layDonHangTheoMaThanhVien(int.Parse(Session["ID"].ToString()));
                List<TinhTrangDonHangCuaNguoiDungDTO> dsTinhTrang = new List<TinhTrangDonHangCuaNguoiDungDTO>();
                for (int i = 0; i < dsDonHang.Count; i++)
                    if (dsDonHang[i].TinhTrang != 0)
                    {
                        TinhTrangDonHangCuaNguoiDungDTO tinhtrang = new TinhTrangDonHangCuaNguoiDungDTO();
                        SanPhamDTO sanpham = SanPhamDAO.laySPTheoMa(dsDonHang[i].MaSanPham);
                        DoanhNghiepDTO doanhnghiep = DoanhNghiepDAO.LayDNTheoMa(sanpham.MaDoanhNghiep);

                        tinhtrang.TenHang = sanpham.TieuDe;
                        tinhtrang.TenDoanhNghiep = doanhnghiep.TenDoanhNghiep;
                        tinhtrang.SoLuong = dsDonHang[i].SoLuong;
                        tinhtrang.TongTien = dsDonHang[i].TongTien;
                        switch (dsDonHang[i].MaLoaiThanhToan)
                        {
                            case 1: tinhtrang.LoaiThanhToan = "NganLuong"; break;
                            case 2: tinhtrang.LoaiThanhToan = "Paypal"; break;
                        }
                        switch (dsDonHang[i].TinhTrang)
                        {
                            case 1: tinhtrang.TinhTrang = "Dang doi thanh toan"; break;
                            case 2: tinhtrang.TinhTrang = "Dang Chuyen Hang"; break;
                        }
                        dsTinhTrang.Add(tinhtrang);
                    }
                dtgridview.DataSource = dsTinhTrang;
                dtgridview.DataBind();
            }
        }
    }
}
